package com.gufe.mapper.user.Exhibition;


import com.gufe.entity.Exhibitions.Reservation;
import org.apache.ibatis.annotations.*;

import java.util.Optional;

@Mapper
public interface ReservationMapper {
    @Select("SELECT * FROM reservations WHERE student_id = #{studentId}")
    Optional<Reservation> findByStudentId(String studentId);

    @Select("SELECT r.* FROM reservations r WHERE r.student_id = #{studentId} AND r.exhibition_id = #{exhibitionId}")
    Optional<Reservation> findByStudentIdAndExhibitionId(@Param("studentId") String studentId, @Param("exhibitionId") Integer exhibitionId);

    @Insert("INSERT INTO reservations (exhibition_id, name, student_id, phone, major) " +
            "VALUES (#{exhibitionId}, #{name}, #{studentId}, #{phone}, #{major})")
    int insert(Reservation reservation);

    @Update("UPDATE reservations SET canceled = #{canceled} WHERE id = #{id}")
    int updateCanceledStatus(Reservation reservation);

    @Select("SELECT r.*, e.name AS exhibitionName FROM reservations r JOIN exhibitions e ON r.exhibition_id = e.id WHERE r.student_id = #{studentId}")
    Optional<Reservation> findReservationWithExhibitionName(String studentId);
}
